<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function isEqual (obj1, obj2) {
            if (typeof obj1 !== typeof obj2) {
                return false;
            }
            if (typeof obj1 !== 'object') {
                return obj1 === obj2;
            }
            if (Object.keys(obj1).length !== Object.keys(obj2).length) {
                return false;
            }
            for (const key in obj1) {
                const value1 = obj1[key];
                const value2 = obj2[key];
                if (!isEqual(value1, value2)) {
                    return false;
                }
            }
            return true;
        }

        // 数组去重
        const arr = [1, 2, {}, 3, 4, {}];

        Array.prototype.unique = function () {
            for (let i = 0; i < this.length; i++) {
                for (let j = i + 1; j < this.length; j++) {
                    const item1 = this[i];
                    const item2 = this[j];
                    console.log(item1, item2, isEqual(item1, item2));
                    if (isEqual(item1, item2)) {
                        this.splice(j, 1);
                        j--;
                    }
                }
            }
        };

        arr.unique();

        console.log(arr);
        console.log(isEqual({}, {}));

    </script>
</body>
</html>